package com.csxy.six.controller;


import com.csxy.six.R;
import com.csxy.six.entity.UserAnnouncement;
import com.csxy.six.service.UserAnnouncementService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户公告关联控制器
 * 提供用户与公告关联关系的RESTful API
 */
@RestController
@RequestMapping("/annoservice/user-announcement")
@Tag(name = "用户公告关联", description = "管理用户与公告的关联关系")
public class UserAnnouncementController {


    @Autowired
    private UserAnnouncementService userAnnouncementService;

    @Operation(summary = "批量绑定用户与公告")
    @PostMapping("/batch")
    public R batchBindUsers(@RequestParam Integer announceId,
                            @RequestBody List<Integer> userIds) {
        return userAnnouncementService.batchBindUsers(announceId, userIds) ? R.ok() : R.error();
    }

    @Operation(summary = "获取公告通知的用户列表")
    @GetMapping("/announcement/{announceId}")
    public R getByAnnounceId(@PathVariable Integer announceId) {
        return R.ok().data("list", userAnnouncementService.lambdaQuery()
                .eq(UserAnnouncement::getAnnounceId, announceId)
                .list());
    }

    @Operation(summary = "获取用户的通知公告列表")
    @GetMapping("/user/{userId}")
    public R getByUserId(@PathVariable Integer userId) {
        return R.ok().data("list", userAnnouncementService.lambdaQuery()
                .eq(UserAnnouncement::getUserId, userId)
                .list());
    }
}